package com.wing.member.controller.app;

import com.wing.common.annotation.LoginMember;
import com.wing.common.utils.JsonResult;
import com.wing.member.model.entity.Member;
import com.wing.member.service.MemberService;
import com.wing.web.utils.LocaleMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author
 */
@Validated
@Api(value = "App-个人中心",tags = {"个人中心"})
@RestController(value = "appMemberController")
@RequestMapping("member/app/member")
public class MemberController {

    @Autowired
    private MemberService memberService;
    @Autowired
    private LocaleMessage localeMessage;


    @ApiOperation(value = "个人中心", notes = "个人中心")
    @GetMapping("/personalCenter")
    public JsonResult personalCenter(@LoginMember Member member) {
        return JsonResult.success(localeMessage.getMessage("common.success"), member);
    }


    @ApiOperation(value = "修改个人信息", notes = "修改个人信息")
    @PostMapping("/updateMemberInfo")
    public JsonResult updateMemberInfo(@LoginMember Member member, String headImg, String nickname, Member.Sex sex, String signature, Boolean isAutoLight) {

        //修改头像
        if(StringUtils.isNotBlank(headImg)){
            member.setHeadImg(headImg);
        }

        //修改昵称
        if(StringUtils.isNotBlank(nickname)){
            member.setNickname(nickname);
        }

        //修改性别
        if(sex != null){
            member.setSex(sex);
        }

        //修改个性签名
        if(StringUtils.isNotBlank(signature)){
            member.setSignature(signature);
        }

        return memberService.updateById(member)
                ? JsonResult.success(localeMessage.getMessage("common.success"))
                : JsonResult.fail(localeMessage.getMessage("common.fail"));
    }


}
